#pragma once

#define CNSL_WND_CB_CMD_EXIT    0
#define CNSL_WND_CB_CD_DIR      1
typedef void (*fnCosolCB)(void* cbCtx, DWORD dwCbType, VOID* para);
class ConsoleEmbWnd
{
public:
    ConsoleEmbWnd();
    virtual ~ConsoleEmbWnd(){Delete();};
public:
    BOOL CanCreate();
    BOOL Create(fnCosolCB cbFn, void* cbCtx);
    VOID Delete();
    HWND GetWindow(){return m_hWnd;};
    BOOL MoveWindow(int X, int Y, int nWidth, int nHeight, BOOL bRepaint);
	BOOL ChangDir(const TCHAR* szDir);
    // must large enough MAX_PATH
    BOOL GetDir(TCHAR* szDir);

private:
static 
    DWORD WINAPI ConSoleThrdFn(LPVOID pthis);
    DWORD ConSoleThrd();

private:
	DWORD GetPromoteStr(TCHAR* szProm, DWORD dwCnt);
	VOID OutputChar(TCHAR c);
	VOID OutputStr(const TCHAR* str);

protected:
    HWND m_hWnd;
    HANDLE m_hOut;
    HANDLE m_hIn;
    COORD m_fontSize;
	TCHAR m_lastPath[MAX_PATH];
	HANDLE m_hCmd;
    HANDLE m_hThrd;
    HANDLE m_evntWndClose;

    fnCosolCB m_fnCosolCB;
    void* m_cbCtx;
};
